import {
  TaskInterimTargetPageQuery,
  TaskInterimTargetResultVO,
  TaskTargetTypeResultVO,
  UploadPdfResult,
  userUpload,
  UploadDetailById,
  UploadDetailByIdOV,
  FileResultVO,
  Tenant,
  DefDictSaveVO,
  checklmportOV,
} from './model/Index';
import { PageParams, PageResult } from '/@/api/model/baseModel';
import { defHttp } from '/@/utils/http/axios';
import type { AxiosRequestConfig } from 'axios';
import qs from 'qs';
import type { AxiosProgressEvent } from 'axios';
import { UploadFileParams } from '/#/axios';
import { RequestEnum } from '/@/enums/httpEnum';
/**
 * 上传
 *
 * @description: Upload interface
 */
//
export const Api = {
  checklmport: {
    url: `/taskInterimTarget/checkImport`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  commitConfirm: {
    url: `/taskInterimTarget/commitConfirm`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  UpdateState: {
    url: `/taskInterimTarget/import`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  UpdateStates: {
    url: `/taskInterimTarget/import`,
    method: RequestEnum.PUT,
  } as AxiosRequestConfig,
  Page: {
    url: `/taskInterimTarget/page`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  upload: {
    url: `/file/anyone/upload`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  AllList: {
    url: `/taskInterimTarget/getInterimList`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  NewUpload: {
    url: '/taskInterimMaterial',
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  del: {
    url: '/taskInterimMaterial',
    method: RequestEnum.DELETE,
  } as AxiosRequestConfig,
  UploadgetDetailById: {
    url: `/taskInterimTarget/getDetailById`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  down: {
    url: `/file/anyone/down`,
    method: RequestEnum.GET,
    responseType: 'blob',
  } as AxiosRequestConfig,
  downLoad: {
    url: `/file/anyone/download`,
    method: RequestEnum.GET,
    responseType: 'blob',
  } as AxiosRequestConfig,
  IddownLoad: {
    url: `/taskInterimMaterial/download`,
    method: RequestEnum.POST,
    responseType: 'blob',
  } as AxiosRequestConfig,
  Save: {
    url: `/defTenant/all`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  taskInterimMark: {
    url: `/taskInterimMark`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  taskInterimMarkPUT: {
    url: `/taskInterimMark`,
    method: RequestEnum.PUT,
  } as AxiosRequestConfig,
  UploadImport: {
    url: `/taskInterimMark/import`,
    method: RequestEnum.POST,
    timeout: 60 * 1000,
  } as AxiosRequestConfig,
  expirationTime: {
    url: `/taskInterimTarget/expirationTime`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
};

export const ExpirationTime = (expirationTime: String[]) =>
  defHttp.request<boolean>({ ...Api.expirationTime, params: { expirationTime } });
export function UploadPdf(
  params: UploadFileParams,
  onUploadProgress: (progressEvent: AxiosProgressEvent) => void,
) {
  params.data = {
    bizType: 'INTERIM_TARGET',
    bucket: 'interim-target',
    storageType: 'MIN_IO',
  };
  return defHttp.uploadFile<UploadPdfResult>(
    {
      url: `/file/anyone/upload`,
      // 60 s
      timeout: 60 * 1000,
      onUploadProgress,
    },
    params,
  );
}
export function UploadImport(
  params: UploadFileParams,
  onUploadProgress?: (progressEvent: AxiosProgressEvent) => void,
) {
  return defHttp.uploadFile<FileResultVO>(
    {
      url: `/taskInterimMark/import`,
      onUploadProgress,
      // 60 s
      timeout: 60 * 1000,
    },
    params,
  );
}
// export const UploadImport = (params: UploadFileParams) =>
//   defHttp.request<FileResultVO>({ ...Api.UploadImport, params });
export const checklmport = () => defHttp.request<checklmportOV>({ ...Api.checklmport });
export const ALLName = () => defHttp.request<Tenant>({ ...Api.Save });

export const NewUpload = (params: userUpload) =>
  defHttp.post<string[]>({ ...Api.NewUpload, params });
export const uploadFiles = (params: UploadFileParams) =>
  defHttp.request<FileResultVO>({ ...Api.UpdateStates, params });
// export const uploadFile = (params: UploadFileParams) =>
//   defHttp.uploadFile<FileResultVO>({ ...Api.UpdateState }, params);
export function uploadFile(
  params: UploadFileParams,
  onUploadProgress?: (progressEvent: AxiosProgressEvent) => void,
) {
  return defHttp.uploadFile<FileResultVO>(
    {
      url: `/taskInterimTarget/import`,
      onUploadProgress,
      // 60 s
      timeout: 60 * 1000,
    },
    params,
  );
}
export const page = (params: PageParams<TaskInterimTargetPageQuery>) =>
  defHttp.request<PageResult<TaskInterimTargetResultVO>>({ ...Api.Page, params });

export const UploadgetDetailById = (params: UploadDetailById) =>
  defHttp.get<UploadDetailByIdOV>({ ...Api.UploadgetDetailById, params });

// export const AllList = (params: TaskInterimTargetPageQuery) =>
//   defHttp.request<TaskInterimTargetResultVO[]>({ ...Api.AllList, params });

export function AllList(params: TaskInterimTargetPageQuery) {
  return defHttp.post<TaskTargetTypeResultVO[]>({
    ...Api.AllList,
    params,
  });
}

export const download = (id: String[] | number[]) =>
  defHttp.request<void>(
    { ...Api.down, params: qs.stringify({ id }, { arrayFormat: 'repeat' }) },
    { isReturnNativeResponse: true },
  );
export const downloadFiles = (ids: string[] | number[]) =>
  defHttp.request<void>(
    { ...Api.downLoad, params: qs.stringify({ ids }, { arrayFormat: 'repeat' }) },
    { isReturnNativeResponse: true },
  );
export const IddownLoad = (ids: String[] | number[], otherId: string) =>
  defHttp.request<void>(
    {
      ...Api.IddownLoad,
      params: { ids, otherId },
      responseType: 'blob',
      timeout: 60 * 60 * 1000,
    },
    { isReturnNativeResponse: true },
  );
// export const IddownLoad = (ids: string[] | number[], otherId: string) =>
//   defHttp.request<void>(
//     { ...Api.IddownLoad, params: qs.stringify({ ids, otherId }, { arrayFormat: 'repeat' }) },
//     { isReturnNativeResponse: true },
//   );
export const taskInterimMarkPUT = (params: DefDictSaveVO) =>
  defHttp.request<UploadDetailByIdOV>({ ...Api.taskInterimMarkPUT, params });
export const taskInterimMark = (params: DefDictSaveVO) =>
  defHttp.request<UploadDetailByIdOV>({ ...Api.taskInterimMark, params });
// export const remove = (params: String[]) => defHttp.request<string[]>({ ...Api.del, params });
export const remove = (params: any[]) => defHttp.request<void>({ ...Api.del, params });
export const commitConfirm = (otherId: string) =>
  defHttp.request<Tenant>({ ...Api.commitConfirm, params: { otherId } });
